package org.atovio.coolexam.mapper;

import org.apache.ibatis.annotations.*;
import org.atovio.coolexam.entity.QuestionOptions;

import java.util.List;
import java.util.Map;

public interface QuestionOptionsMapper {

    @Insert("""
            insert into t_question_options (id, question_id, content, is_correct, `order`)
            values (#{id},#{questionId},#{content},#{isCorrect},#{order});
            """)
    int insert(QuestionOptions questionOptions);

    @Select("select * from t_question_options;")
    List<QuestionOptions> selectAll();

    @Select("select * from t_question_options where id = #{id};")
    QuestionOptions selectById(Integer id);

    @Select("select * from t_question_options where question_id = #{questionId};")
    List<QuestionOptions> selectByQuestionId(Integer questionId);

    /**
     * 根据自定义条件查询记录条数
     *
     * @param criteria 自定义条件
     * @return 记录条数
     */
    int selectCountSelective(@Param("criteria") Map<String, Object> criteria);

    @Update("update t_question_options set question_id = #{questionId} where id = #{id};")
    int updateQuestionIdById(Integer id, Integer questionId);

    @Update("update t_question_options set content  = #{content} where id = #{id};")
    int updateContentById(Integer id, String content);

    @Update("update t_question_options set  is_correct = #{isCorrect} where id = #{id};")
    int updateIsCorrectById(Integer id, Integer isCorrect);

    @Update("update t_question_options set `order` = #{order} where id = #{id};")
    int updateOrderById(Integer id, Integer order);

    @Delete("delete from t_question_options where id = #{id};")
    int deleteById(Integer id);

    @Delete("delete from t_question_options where question_id = #{questionId};")
    int deleteByQuestionId(Integer questionId);
}
